package com.my.content.ui_homework.fragment;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.my.content.ui_homework.fragment.FindPage.FindSaleFragment;
import com.my.content.ui_homework.fragment.FirstPage.FirstPagerFragment;
import com.my.content.ui_homework.fragment.HomePage.HomePageFragment;
import com.my.content.ui_homework.fragment.StarSale.StarSaleFragment;

/**
 * Created by Lenovo on 2016/11/12.
 */

public class FragmentFactory {
    private static final int FRAGMENT_FIRST = 0;
    private static final int FRAGMENT_STAR = 1;
    private static final int FRAGMENT_HOME = 2;
    private static final int FRAGMENT_FIND = 3;
    private static final int FRAGMENT_MINE = 4;
    private static SparseArray<Fragment> fragments = new SparseArray<>();

    public  static Fragment createFragment(int index){
        Fragment fragment = fragments.get(index);
        if(fragment == null){
            switch (index){
                case FRAGMENT_FIRST:
                    fragment = new FirstPagerFragment();
                    break;
                case FRAGMENT_STAR:
                    fragment = new StarSaleFragment();
                    break;
                case FRAGMENT_HOME:
                    fragment = new HomePageFragment();
                    break;
                case FRAGMENT_FIND:
                    fragment = new FindSaleFragment();
                    break;
                case FRAGMENT_MINE:
                    fragment = new MinePageFragment();
                    break;
            }
            fragments.put(index,fragment);
        }
        return fragment;
    }
}
